package com.yilu.driver.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;

import com.is.ui.filter.adapter.FilterMenuAdapter;
import com.is.ui.filter.interfaces.OnFilterDoneListener;
import com.is.ui.filter.util.UIUtil;
import com.is.ui.filter.view.doubleGrid.DoubleGridView;

import java.util.ArrayList;
import java.util.List;


/**
 * 成绩登记筛选（科目、期数）
 * Created by Administrator on 2016/10/28 0028.
 */

public class DropReistrationAdapter implements FilterMenuAdapter {
    private final Context mContext;
    private OnFilterDoneListener onFilterDoneListener;
    private String[] titles;

    public DropReistrationAdapter(Context mContext, OnFilterDoneListener onFilterDoneListener, String[] titles) {
        this.mContext = mContext;
        this.onFilterDoneListener = onFilterDoneListener;
        this.titles = titles;

    }

    @Override
    public int getMenuCount() {
        return titles.length;
    }

    @Override
    public String getMenuTitle(int position) {
        return titles[position];
    }

    @Override
    public int getBottomMargin(int position) {
        if (position == 3) {
            return 0;
        }
        return UIUtil.dp(mContext, 140);
    }

    @Override
    public View getView(int position, FrameLayout parentContainer) {
        View view = parentContainer.getChildAt(position);
        switch (position) {
            case 0:
                view = createDoubleGrid();
                break;
        }
        return view;
    }

    private View createDoubleGrid() {
        DoubleGridView doubleGridView = new DoubleGridView(mContext);
        doubleGridView.setOnFilterDoneListener(onFilterDoneListener);


        List<String> phases = new ArrayList<>();
        for (int i = 0; i < 10; ++i) {
            phases.add("3top" + i);
        }
        doubleGridView.setTopGridData(phases);

        List<String> areas = new ArrayList<>();
        for (int i = 0; i < 10; ++i) {
            areas.add("3bottom" + i);
        }
        doubleGridView.setBottomGridList(areas);

        return doubleGridView;
    }

    private void onFilterDone() {
        if (onFilterDoneListener != null) {
            onFilterDoneListener.onFilterDone(0, "", "");
        }
    }
}
